package com.sxwl.auth.netty;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.concurrent.EventExecutorGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author reading
 * @Description TODO
 * @Date 2020/4/12 21:18
 */
@Slf4j
public class CheckIsInvalid  extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object ev) throws Exception {
        if(ev instanceof IdleStateEvent) {
            IdleStateEvent idleStateEvent = (IdleStateEvent)ev;
            if(idleStateEvent.state() == IdleState.READER_IDLE) {
                log.info("读空闲");
            }
            else if(idleStateEvent.state() == IdleState.WRITER_IDLE) {
                log.info("写空闲");
            }
            else if(idleStateEvent.state() == IdleState.ALL_IDLE) {
                log.info("读空闲*********写空闲");
                ctx.channel().close();
            }
        }
    }
}
